package com.gzck.gzck_verson2.controller;

import com.gzck.gzck_verson2.pojo.GFactor;
import com.gzck.gzck_verson2.service.IGFactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/g-factor")
public class GFactorController {

    @Autowired
    private IGFactorService factorService;

    // 添加要素信息
    @PostMapping("/add")
    public boolean addFactor(@RequestBody GFactor factor) {
        return factorService.save(factor);
    }

    // 删除要素信息
    @DeleteMapping("/delete/{id}")
    public boolean deleteFactor(@PathVariable Long id) {
        return factorService.removeById(id);
    }

    // 更新要素信息
    @PutMapping("/update")
    public boolean updateFactor(@RequestBody GFactor factor) {
        return factorService.updateById(factor);
    }

    // 查询单个要素信息
    @GetMapping("/{id}")
    public GFactor getFactor(@PathVariable Long id) {
        return factorService.getById(id);
    }

    // 查询所有要素信息
    @GetMapping("/all")
    public List<GFactor> getAllFactors() {
        return factorService.list();
    }
}
